//package center.leon.zoowebsentinel.spi;
//
//import center.leon.zoowebsentinel.holder.ApplicationContextHolder;
//import center.leon.zoowebsentinel.holder.SentinelHolder;
//import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
//import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
//import com.alibaba.csp.sentinel.init.InitFunc;
//import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
//import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.TypeReference;
//import com.alibaba.nacos.api.PropertyKeyConst;
//
//import java.util.List;
//import java.util.Properties;
//
///**
// * @author xuxinmin
// */
//public class DataSourceInitFunc implements InitFunc {
//
//    @Override
//    public void init() throws Exception {
////        SentinelHolder sentinelHolder = ApplicationContextHolder.getBean(SentinelHolder.class);
////        final String serverAddr = sentinelHolder.getWeb().getDatasource().getNacos().getFlow().getServerAddr();
////        final String namespace = sentinelHolder.getWeb().getDatasource().getNacos().getFlow().getNamespace();
////        final String dataId = sentinelHolder.getWeb().getDatasource().getNacos().getFlow().getDataId();
////        final String groupId = sentinelHolder.getWeb().getDatasource().getNacos().getFlow().getGroupId();
////
////        Properties properties = DataSourceInitFunc.buildProperties(serverAddr, namespace);
////        ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new NacosDataSource<>(properties, groupId, dataId,
////            source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}));
////        FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
//    }
//
//    private static Properties buildProperties(String serverAddr, String namespace) {
//        Properties properties = new Properties();
//        properties.put(PropertyKeyConst.NAMESPACE, namespace);
//        properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
//        return properties;
//    }
//
//}